<html>
<head><meta charset="utf-8"><title>root-database · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html">root-database</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195207219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/195207219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#195207219">(Apr 24 2020 at 15:47)</a>:</h4>
<p>Hey, I am having some issues trying to work with the <code>RootDatabase</code>.</p>
<div class="codehilite"><pre><span></span><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">analysis_host</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">WorldState</span>::<span class="n">new</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="n">vec</span><span class="o">!</span><span class="p">[</span><span class="n">cur_dir</span><span class="p">],</span><span class="w"></span>
<span class="w">        </span><span class="n">workspaces</span><span class="p">,</span><span class="w"> </span><span class="c1">// built from cur_dir</span>
<span class="w">        </span><span class="nb">None</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="o">&amp;</span><span class="p">[],</span><span class="w"></span>
<span class="w">        </span><span class="n">Watch</span><span class="p">(</span><span class="kc">false</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="n">Config</span>::<span class="n">default</span><span class="p">(),</span><span class="w"></span>
<span class="w">    </span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">analysis_host</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">snapshot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">analysis_host</span><span class="p">.</span><span class="n">analysis</span><span class="p">();</span><span class="w"></span>

<span class="w">    </span><span class="n">snapshot</span><span class="p">.</span><span class="n">with_db</span><span class="p">(</span><span class="o">|</span><span class="n">db</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">for</span><span class="w"> </span><span class="o">&amp;</span><span class="n">root</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">db</span><span class="p">.</span><span class="n">local_roots</span><span class="p">().</span><span class="n">iter</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="kd">let</span><span class="w"> </span><span class="n">sr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">db</span><span class="p">.</span><span class="n">source_root</span><span class="p">(</span><span class="n">root</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:#?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">sr</span><span class="p">);</span><span class="w"></span>

<span class="w">                </span><span class="k">for</span><span class="w"> </span><span class="n">file_id</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">sr</span><span class="p">.</span><span class="n">walk</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:#?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">file_id</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">})</span><span class="w"></span>
</pre></div>


<p>The output is:</p>
<div class="codehilite"><pre><span></span>SourceRootId(
    23,
)
SourceRoot {
    is_library: false,
    files: {},
}
</pre></div>


<p>What happened to the files that were supposed to be in the source root?</p>



<a name="195209978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/195209978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#195209978">(Apr 24 2020 at 16:07)</a>:</h4>
<p><code>WorldState</code> is somehow the issue. I loaded the <code>AnalysisHost</code> using <code>cli::load_cargo</code> and it worked</p>



<a name="195353041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/195353041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#195353041">(Apr 26 2020 at 21:16)</a>:</h4>
<p>The files are loaded asynchronosly</p>



<a name="195353047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/195353047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#195353047">(Apr 26 2020 at 21:17)</a>:</h4>
<p>Ie, creating world-state <em>starts</em> the process of scanning files, but you need to handle vfs tasks to complete it</p>



<a name="195353813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/195353813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#195353813">(Apr 26 2020 at 21:39)</a>:</h4>
<p>Thanks</p>



<a name="196101257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/196101257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#196101257">(May 03 2020 at 12:33)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> Just to confirm, looks like <code>load_cargo</code> is not loading <code>library_roots</code>. Is that right?</p>



<a name="196114541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/196114541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#196114541">(May 03 2020 at 17:53)</a>:</h4>
<p>Maybe not loading libraries is the reason I am getting the following error:</p>



<a name="196114602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/196114602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#196114602">(May 03 2020 at 17:54)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="w">    </span><span class="n">analysis</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">with_db</span><span class="p">(</span><span class="o">|</span><span class="n">db</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">semantics</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Semantics</span>::<span class="n">new</span><span class="p">(</span><span class="n">db</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="c1">// stuff</span>
<span class="w">           </span><span class="n">semantics</span><span class="p">.</span><span class="n">resolve_method_call</span><span class="p">(</span><span class="o">&amp;</span><span class="n">method_call_expr</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="196114608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/196114608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#196114608">(May 03 2020 at 17:54)</a>:</h4>
<div class="codehilite"><pre><span></span><code>thread &#39;main&#39; panicked at &#39;

Failed to lookup METHOD_CALL_EXPR@91..14349 in this Semantics.
Make sure to use only query nodes, derived from this instance of Semantics.
root node:   SOURCE_FILE@0..14424
known nodes:

&#39;, &lt;::std::macros::panic macros&gt;:5:6
</code></pre></div>



<a name="196125501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/root-database/near/196125501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/root-database.html#196125501">(May 03 2020 at 22:01)</a>:</h4>
<p>I have got the visitor we were talking about working to get some basic code analysis allowed but I am blocked on the above issue trying to get semantics info incorporated into the visitor</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>